{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "acc6aeb5-9564-4407-8c7a-6303f9d6c1f7",
   "metadata": {},
   "source": [
    "#### ❇️ Pandas 🐼 Describe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ebd43904-e02a-46f4-abba-102c76655e65",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7a97a7b2-e816-4304-8b9f-201453a48693",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>Name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2013-02-08</td>\n",
       "      <td>45.07</td>\n",
       "      <td>45.35</td>\n",
       "      <td>45.00</td>\n",
       "      <td>45.08</td>\n",
       "      <td>1824755</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2013-02-11</td>\n",
       "      <td>45.17</td>\n",
       "      <td>45.18</td>\n",
       "      <td>44.45</td>\n",
       "      <td>44.60</td>\n",
       "      <td>2915405</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         date   open   high    low  close   volume Name\n",
       "0  2013-02-08  45.07  45.35  45.00  45.08  1824755    A\n",
       "1  2013-02-11  45.17  45.18  44.45  44.60  2915405    A"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stocks = pd.read_csv(\"stocks.csv\")\n",
    "stocks.head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "61dc597f-c854-4e69-ac3d-3f5c274bb1f2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>1259.000000</td>\n",
       "      <td>1259.000000</td>\n",
       "      <td>1259.000000</td>\n",
       "      <td>1259.000000</td>\n",
       "      <td>1.259000e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>49.187863</td>\n",
       "      <td>49.600059</td>\n",
       "      <td>48.782026</td>\n",
       "      <td>49.202025</td>\n",
       "      <td>2.338039e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>9.244798</td>\n",
       "      <td>9.264168</td>\n",
       "      <td>9.197698</td>\n",
       "      <td>9.229804</td>\n",
       "      <td>1.400161e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>33.180000</td>\n",
       "      <td>34.060000</td>\n",
       "      <td>33.115000</td>\n",
       "      <td>33.370000</td>\n",
       "      <td>5.328630e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>41.515000</td>\n",
       "      <td>41.870000</td>\n",
       "      <td>41.260000</td>\n",
       "      <td>41.560000</td>\n",
       "      <td>1.533018e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>46.640000</td>\n",
       "      <td>47.000000</td>\n",
       "      <td>46.341000</td>\n",
       "      <td>46.700000</td>\n",
       "      <td>2.003109e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>56.435000</td>\n",
       "      <td>56.935000</td>\n",
       "      <td>56.025000</td>\n",
       "      <td>56.495000</td>\n",
       "      <td>2.718401e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>74.480000</td>\n",
       "      <td>75.000000</td>\n",
       "      <td>74.300000</td>\n",
       "      <td>74.820000</td>\n",
       "      <td>1.814641e+07</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              open         high          low        close        volume\n",
       "count  1259.000000  1259.000000  1259.000000  1259.000000  1.259000e+03\n",
       "mean     49.187863    49.600059    48.782026    49.202025  2.338039e+06\n",
       "std       9.244798     9.264168     9.197698     9.229804  1.400161e+06\n",
       "min      33.180000    34.060000    33.115000    33.370000  5.328630e+05\n",
       "25%      41.515000    41.870000    41.260000    41.560000  1.533018e+06\n",
       "50%      46.640000    47.000000    46.341000    46.700000  2.003109e+06\n",
       "75%      56.435000    56.935000    56.025000    56.495000  2.718401e+06\n",
       "max      74.480000    75.000000    74.300000    74.820000  1.814641e+07"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stocks.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "60594fcb-aaba-42e1-b7da-b2e4c4018295",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style type=\"text/css\">\n",
       "#T_41e4f_row5_col0 {\n",
       "  background-color: magenta;\n",
       "}\n",
       "</style>\n",
       "<table id=\"T_41e4f\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th class=\"blank level0\" >&nbsp;</th>\n",
       "      <th id=\"T_41e4f_level0_col0\" class=\"col_heading level0 col0\" >open</th>\n",
       "      <th id=\"T_41e4f_level0_col1\" class=\"col_heading level0 col1\" >high</th>\n",
       "      <th id=\"T_41e4f_level0_col2\" class=\"col_heading level0 col2\" >low</th>\n",
       "      <th id=\"T_41e4f_level0_col3\" class=\"col_heading level0 col3\" >close</th>\n",
       "      <th id=\"T_41e4f_level0_col4\" class=\"col_heading level0 col4\" >volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th id=\"T_41e4f_level0_row0\" class=\"row_heading level0 row0\" >count</th>\n",
       "      <td id=\"T_41e4f_row0_col0\" class=\"data row0 col0\" >1259.000000</td>\n",
       "      <td id=\"T_41e4f_row0_col1\" class=\"data row0 col1\" >1259.000000</td>\n",
       "      <td id=\"T_41e4f_row0_col2\" class=\"data row0 col2\" >1259.000000</td>\n",
       "      <td id=\"T_41e4f_row0_col3\" class=\"data row0 col3\" >1259.000000</td>\n",
       "      <td id=\"T_41e4f_row0_col4\" class=\"data row0 col4\" >1259.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_41e4f_level0_row1\" class=\"row_heading level0 row1\" >mean</th>\n",
       "      <td id=\"T_41e4f_row1_col0\" class=\"data row1 col0\" >49.187863</td>\n",
       "      <td id=\"T_41e4f_row1_col1\" class=\"data row1 col1\" >49.600059</td>\n",
       "      <td id=\"T_41e4f_row1_col2\" class=\"data row1 col2\" >48.782026</td>\n",
       "      <td id=\"T_41e4f_row1_col3\" class=\"data row1 col3\" >49.202025</td>\n",
       "      <td id=\"T_41e4f_row1_col4\" class=\"data row1 col4\" >2338038.906275</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_41e4f_level0_row2\" class=\"row_heading level0 row2\" >std</th>\n",
       "      <td id=\"T_41e4f_row2_col0\" class=\"data row2 col0\" >9.244798</td>\n",
       "      <td id=\"T_41e4f_row2_col1\" class=\"data row2 col1\" >9.264168</td>\n",
       "      <td id=\"T_41e4f_row2_col2\" class=\"data row2 col2\" >9.197698</td>\n",
       "      <td id=\"T_41e4f_row2_col3\" class=\"data row2 col3\" >9.229804</td>\n",
       "      <td id=\"T_41e4f_row2_col4\" class=\"data row2 col4\" >1400160.998314</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_41e4f_level0_row3\" class=\"row_heading level0 row3\" >min</th>\n",
       "      <td id=\"T_41e4f_row3_col0\" class=\"data row3 col0\" >33.180000</td>\n",
       "      <td id=\"T_41e4f_row3_col1\" class=\"data row3 col1\" >34.060000</td>\n",
       "      <td id=\"T_41e4f_row3_col2\" class=\"data row3 col2\" >33.115000</td>\n",
       "      <td id=\"T_41e4f_row3_col3\" class=\"data row3 col3\" >33.370000</td>\n",
       "      <td id=\"T_41e4f_row3_col4\" class=\"data row3 col4\" >532863.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_41e4f_level0_row4\" class=\"row_heading level0 row4\" >50%</th>\n",
       "      <td id=\"T_41e4f_row4_col0\" class=\"data row4 col0\" >46.640000</td>\n",
       "      <td id=\"T_41e4f_row4_col1\" class=\"data row4 col1\" >47.000000</td>\n",
       "      <td id=\"T_41e4f_row4_col2\" class=\"data row4 col2\" >46.341000</td>\n",
       "      <td id=\"T_41e4f_row4_col3\" class=\"data row4 col3\" >46.700000</td>\n",
       "      <td id=\"T_41e4f_row4_col4\" class=\"data row4 col4\" >2003109.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_41e4f_level0_row5\" class=\"row_heading level0 row5\" >90%</th>\n",
       "      <td id=\"T_41e4f_row5_col0\" class=\"data row5 col0\" >61.256000</td>\n",
       "      <td id=\"T_41e4f_row5_col1\" class=\"data row5 col1\" >61.584000</td>\n",
       "      <td id=\"T_41e4f_row5_col2\" class=\"data row5 col2\" >60.760000</td>\n",
       "      <td id=\"T_41e4f_row5_col3\" class=\"data row5 col3\" >61.194000</td>\n",
       "      <td id=\"T_41e4f_row5_col4\" class=\"data row5 col4\" >3714659.200000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_41e4f_level0_row6\" class=\"row_heading level0 row6\" >max</th>\n",
       "      <td id=\"T_41e4f_row6_col0\" class=\"data row6 col0\" >74.480000</td>\n",
       "      <td id=\"T_41e4f_row6_col1\" class=\"data row6 col1\" >75.000000</td>\n",
       "      <td id=\"T_41e4f_row6_col2\" class=\"data row6 col2\" >74.300000</td>\n",
       "      <td id=\"T_41e4f_row6_col3\" class=\"data row6 col3\" >74.820000</td>\n",
       "      <td id=\"T_41e4f_row6_col4\" class=\"data row6 col4\" >18146408.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x7faf8f07f790>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 💫 An important parameter is percentile\n",
    "# 👉 Note: The highlighted value states that 90% of the values in open are <= 61.256\n",
    "perc =[.50, .90]\n",
    "subsets = pd.IndexSlice[['90%'], 'open']\n",
    "stocks.describe(percentiles = perc).style.applymap(lambda x: \"background-color: magenta\", subset=subsets)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "df426da9-1862-4cc7-ab0c-1269e4a11c61",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "env_twitter",
   "language": "python",
   "name": "env_twitter"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
